<template>
  <div>
    <div class="user-select">
      <div class="user-select-left">
        <el-input placeholder="请输入搜索内容" v-model="searchValue"></el-input>
        <el-checkbox-group v-model="checkedUser">
          <el-checkbox v-for="(item, i) in filterUser" :key="i" :label="item">
            {{ item }}
          </el-checkbox>
        </el-checkbox-group>
      </div>
      <div class="user-select-right">
        <div>
          <span>已选成员：{{ checkedUser.length }}名成员</span>
        </div>
        <div class="user-select-list">
          <div class="user-item" v-for="(item, i) in checkedUser" :key="i">
            <el-avatar size="small" shape="square" src=""></el-avatar>
            <span>{{ item }}</span>
            <i class="el-icon-close user-item-del" @click="delItem(item)"></i>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>
<script>
export default {
  name: "SelectBoxSearch",
  components: {},
  data() {
    return {
      checkedUser: [],
      userList: ["用户1", "用户2", "用户3"],
      searchValue: "",
    };
  },
  created() {},
  computed: {
    // 搜索过滤
    filterUser() {
      return this.userList.filter((item) => item.includes(this.searchValue));
    },
  },
  methods: {
    delItem(item) {
      this.checkedUser = this.checkedUser.filter((v) => v !== item);
    },
  },
};
</script>
<style lang="scss" scoped>
.user-select {
  display: flex;
  .user-select-left {
    width: 300px;
    border: 1px solid #ebeef5;
    margin-right: 20px;
    padding: 20px;
    .el-checkbox-group {
      margin-top: 10px;
      display: flex;
      flex-direction: column;
      ::v-deep .el-checkbox {
        margin-bottom: 10px;
      }
    }
  }
  .user-select-right {
    flex: 1;
    padding: 20px;
    border: 1px solid #ebeef5;
    > div {
      display: flex;
      justify-content: space-between;
      margin-bottom: 20px;
      align-items: center;
    }
    .user-select-list {
      display: flex;
      flex-direction: column;
      align-items: flex-start;

      .user-item {
        display: flex;
        align-items: center;
        margin-bottom: 10px;
        position: relative;
        width: 100%;

        span {
          margin-left: 10px;
        }
        .user-item-del {
          cursor: pointer;
          position: absolute;
          right: 0;
        }
      }
    }
  }
}
</style>
